package club.xinghe.servlet.teacher;

import club.xinghe.biz.TkBiz;
import club.xinghe.entity.Pdt;
import club.xinghe.entity.Tk;
import club.xinghe.entity.Xzt;
import club.xinghe.util.JsonServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/teacher/ShowExamServlet")
public class ShowExamServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String estring = request.getParameter("estring");
        TkBiz tkBiz = new TkBiz();
        //卷子中的所有题
        List<Tk> tkList = tkBiz.showEtk(estring);

        //选择题
        List<Xzt> xzdList = new ArrayList<>();
        //判断题
        List<Pdt> pddList = new ArrayList<>();

        for (int i = 0; i < tkList.size(); i++) {
            if (tkList.get(i).getStyle().getStyleId()==2){
                Pdt pdt = null;
                String[] u = tkList.get(i).gettContent().split("#");
                pdt = new Pdt(tkList.get(i).gettId(),u[0],tkList.get(i).gettAnswer());
                pddList.add(pdt);
            }
            if (tkList.get(i).getStyle().getStyleId()==1){
                Xzt xzt = null;
                String[] x = tkList.get(i).gettContent().split("#");
                xzt = new Xzt(tkList.get(i).gettId(),x[0],x[1],x[2],x[3],x[4],tkList.get(i).gettAnswer());
                xzdList.add(xzt);
            }
        }

        Map<String,Object> maps = new HashMap<>();
        maps.put("xzdList",xzdList);
        maps.put("pddList",pddList);
        JsonServlet.getJson(request,response,maps);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
